package net.huashitong.threeSeven.controller;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.utils.ObjectUtils;
import net.huashitong.threeSeven.entity.IndexData;
import net.huashitong.threeSeven.filter.IndexDataFilter;
import net.huashitong.threeSeven.filter.RequestModelFilter;
import net.huashitong.threeSeven.service.IndexDataService;
import net.huashitong.threeSeven.service.IndexWithAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Filter;

@Controller
@RequestMapping("/thirdIndustry")
public class ThirdIndustryController extends JsonBaseController {

    @Autowired
    private IndexDataService indexDataService;
    @Autowired
    private IndexWithAreaService indexWithAreaService;

    @Override
    protected String getView(String s) {
        return null;
    }

    /**
     * 三产七大指标       首页
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getindex", method = RequestMethod.POST)
    public Message getIndex(@RequestBody IndexDataFilter filter) {
        Map<String, Object> result = indexDataService.getIndex(filter);
        if (ObjectUtils.isNotBlank(result)) {
            return coverMessage("200", "获取成功", result);
        } else {
            return coverMessage("201", "获取失败，无数据");
        }
    }

    /**
     * 三产七大指标       二级
     * 参数：indexCode（必填）、dateTime（必填）
     * 第一张图，截止时间：deadline(非必填)
     *
     * @param filter
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getindexdetail", method = RequestMethod.POST)
    public Message getIndexDetail(@RequestBody RequestModelFilter filter) {
        Map<String, Object> resultMap = new HashMap<>();
        if (ObjectUtils.isBlank(filter.getIndexCode())) {
            filter.setIndexCode("A001");
        }
        if("A001".equals(filter.getIndexCode())){
            Map<String, Object> resTwo = indexWithAreaService.getIndexDetailTwo(filter);
            resultMap.put("resTwo", resTwo);
        }
        Map<String, Object> resOne = indexWithAreaService.getIndexDetailOne(filter);
        Map<String, Object> resThree = indexWithAreaService.getIndexDetailThree(filter);
        resultMap.put("resOne", resOne);
        resultMap.put("resThree", resThree);

        return coverMessage("200", "成功获取数据", resultMap);
    }

    /**
     * 第三级页面
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryThirdYeMian",method = RequestMethod.POST)
    public Message queryThirdYeMian(@RequestBody RequestModelFilter filter){
        Map<String, Object> result = null;

        if("1".equals(filter.getType())){
            result = indexWithAreaService.queryThirdGrade(filter);
        }else {
            if(filter.getIndexCode().length()>4){
                filter.setIndexCode(filter.getIndexCode().substring(0,4));
                result = indexWithAreaService.queryThirdGrade(filter);

            }else{
                result = indexWithAreaService.queryThirdGrade(filter);
            }
        }

        return coverMessage("200", "成功获取数据", result);
    }
}
